import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios'
import VueAxios from 'vue-axios'
import { Message } from 'element-ui'
import message from 'element-ui/packages/message'
Vue.use(VueAxios, axios)
Vue.use(ElementUI);
Vue.config.productionTip = false
axios.defaults.baseURL = 'http://shop.zhuox.net/api/private/v1/'
// 请求拦截器
axios.interceptors.request.use(
	config => {
		if (config.url != 'login') {
			config.headers.Authorization = sessionStorage.getItem('token');
		}
		return config
	}
);

// 响应拦截器
axios.interceptors.response.use(
	config => {
		if (config.data.meta.status.msg == '无效token') {
			router.push('/login');
			Message.error('请重新登录');
		}
		return config
	}
);

new Vue({
	router,
	store,
	render: h => h(App)
}).$mount('#app')
